"""DjangoLearning URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/1.11/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  url(r'^$', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  url(r'^$', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.conf.urls import url, include
    2. Add a URL to urlpatterns:  url(r'^blog/', include('blog.urls'))

    由于路由的解析是由上至下的,因此在匹配路由时需考虑前面的路由规则是否会覆盖后面的规则(即需要匹配后面的路由但实际上是匹配的前路由)
"""
from django.conf.urls import url, include
from django.contrib import admin
from rest_framework.documentation import include_docs_urls

import users_1.urls

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    # 使用include来将子应用users里的全部路由包含进工程路由中
    url(r'^users_1/', include('users_1.urls', namespace='users_1')),
    # 或者使用include直接传递应用的urls模块,这里需先导入应用的路由
    url(r'^users_1/', include(users_1.urls)),
    url(r'^bookmanagment_2/', include('bookmanagment_2.urls', namespace='bookmanagment_2')),  # 反向解析时用namespace(reserve)
    url(r"^bkapp_3/", include("bkapp_3.urls")),
    # 添加接口文档路径,参数title为接口文档网站的标题,视图集ViewSet中的retrieve名称在接口文档网站中叫做read,接口文档中参数的Description需要在模型类或序列化器类的字段中以help_text选项定义
    url(r'^docs/', include_docs_urls(title='My API title')),
]


"""
urlpatterns = [
    url(r'^users_1/',include('users_1.urls', namespace='users_1')),
    url(r'^index/$', views.index, name='index'),
    url(r'^say/', views.say, name='say'),
]
namespace='users_1' 定义路由的命名空间, 用于指定users.urls中定义的路由均属于namespace指明的users名下, 避免不同应用中的路由使用相同的名字发生冲突
name='say'  定义普通路由的名字, 该参数是全局的,因此整个urlpatterns里只能有一个唯一的name, 理由同上

其次: 考虑到防止使用某路由时直接写死, 加上name参数后可以通过该参数进行查找路由, 使得就算该路由路径匹配规则改变了,templates里的html也可以访问到而不用一个个去修改使用该路由的地方
    如: <a href="/index">首页</a>   -------->>>   <a href="{ % url 'appname:index' % }">首页</a>
    这里appname表示该url所在的app的name, index表示该路由的name参数的值
"""